package com.yd.mq.receiver.core;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.yd.mq.parse.utils.AlarmParseUtils;

/**
 * 消息监听
 */
@Component
public class MessageListener {

	/* 并发处理 */
//	private ListeningExecutorService	executorService	= MoreExecutors
//			.listeningDecorator(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 6));

	/**
	 * 日志处理
	 */
	private Logger	log	= Logger.getLogger(this.getClass().getName());

	/**
	 * 解析程序入口类
	 */
	@Autowired
	private Msg2FileUtils fileUtils;

	@Autowired
	private AlarmParseUtils	parseUtil;

	@JmsListener(destination = "${project.mq.queue.name}")
	public void receive(byte[] msg) {
		try {
			final String msgStr = new String(msg, "GBK");
//			log.info("-写入文件监听到的消息内容为: " + msgStr);
			fileUtils.writeFileInit(msgStr);
			log.info("消息内容入库...");
			parseUtil.init(msgStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}